package com.heartech.prediciton_wx.controller.wxparameter;

import com.heartech.prediciton_wx.constant.WxCode;
import com.heartech.prediciton_wx.entity.qrcode.QrStrState;
import com.heartech.prediciton_wx.entity.token.AccessToken;
import com.heartech.prediciton_wx.service.token.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/wxpublic")
public class AccessTokenController {
    @Autowired
    private TokenService tokenService;
    @GetMapping("/access_token/")
    public ResponseEntity<AccessToken> getAccessonToken() {
        String url = WxCode.get_token;
        AccessToken response = tokenService.getAccessToken(url);

        if (response != null) {
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }
}
